<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <!-- 以借助 script 标签直接通过 CDN 来使用 Vue： -->
    <script src="./JS/vue.js"></script>
  </head>
  <body>
    <div id="app">
      <h1>学校信息</h1>
      <h2>学校名称：{{name}}</h2>
      <h2>学校地址：{{address}}</h2>
      <hr />
      <h1>人员信息</h1>
      <button @click="addSex">添加性别属性，默认男</button>
      <h2>姓名：{{student.name}}</h2>
      <h2 v-if="student.sex">性别:{{student.sex}}</h2>
      <h2>年龄：真实{{student.age.rAge}},对外{{student.age.sAge}}</h2>
      <h2>朋友</h2>
      <ul>
        <li v-for="f,index in student.friends" :key="index">
          {{f.name}}--{{f.age}}
        </li>
      </ul>
    </div>

    <script>
      var app = new Vue({
        el: "#app",
        data: {
          name: "有有有",
          address: "北京",
          student: {
            name: "tom",
            age: {
              rAge: 40,
              sAge: 29,
            },
            friends: [
              {
                name: "jerry",
                age: 35,
              },
              {
                name: "tony",
                age: 36,
              },
            ],
          },
        },
        methods: {
          addSex() {
            console.log(this);
            // this.student.sex = "男";
            Vue.set(this.student, "sex", "男");
          },
        },
      });
    </script>
  </body>
</html>
